<template>
  <div class="header">
    <van-nav-bar
      title="收获地址列表"
      right-text="确认"
      left-arrow
      @click-right="onConfirm"
      @click-left="Pages()"
    >
    </van-nav-bar>
    <van-address-list
      v-model="chosenAddressId"
      :list="addressList"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>
<script>
import { Dialog, Toast } from "vant";
import axios from "axios";
export default {
  data() {
    return {
      addressList: [],
      chosenAddressId: "1",
    };
  },
  mounted() {
    this.getData();
    this.chosenAddressId = String(this.$route.query.id);
  },
  methods: {
    onAdd() {
      Toast("新增地址");
      this.$router.push({
        path: "/address",
        query: {
          type: "add",
        },
      });
    },

    onEdit(item) {
      this.$router.push({
        path: "/address",
        query: {
          type: "edit",
          data: item,
        },
      });
    },
    Pages(path) {
      this.$router.go(-1);
    },
    onConfirm() {
      this.$router.push({
        path: "/pay",
        query: {
          allCheckedGoodsList: this.$route.query.allCheckedGoodsList,
        },
      });
      // this.$router.go(-1)
      Toast("选择成功");
    },
    getData() {
      axios({
        url: "http://127.0.0.1:3000/address/list",
        method: "get",
      }).then((res) => {
        this.addressList = res.data;
        console.log("aaa", this.addressList);
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.header {
  background: #f2f2f2;
  height: 100%;
}
</style>>



